<?php
/**
 * Created by Command.
 * User: Vito
 */

namespace app\admin\curd\room_lease_record;

use app\common\curd\Index;
use think\db\Query;
class RoomLeaseRecordIndex extends Index
{
    /**
     * 关键词查询指定字段
     * @var string[]
     */
    protected $keywordQueryArgs = [];
    //追加标签数据
    protected $labelCallback = [
        'get_sex_enum'      => ['name' => '性别'],
        'get_alone_enum'    => ['name' => '状态'],
        'get_status_enum'   => ['name' => '状态']
    ];
    //查询条件
    protected $where = [];
    //字段
    protected $field = [];
    //排除字段
    protected $withoutField = false;
    //关联
    protected $with = [
      'user'
    ];
    /**
     * 需要查询条件的字段
     * 数据库字段和参数字段名不一样 'db_field' => 'param_field'
     * 数据库字段和参数字段名一样 'field'
     * @var array
     */
    protected $queryField = [];
    protected $middleware = [
      'middleWhere'
    ];

  protected function middleWhere($next)
  {
    $kw = $this->request['kw'];
    if ($kw) {
      $this->field = [
        'RoomLeaseRecord.id' => 'id',
        'RoomLeaseRecord.*'
      ];
    }
    return $next();
  }
  protected function queryCallback(Query $query)
  {
    // halt($this->request);
    $kw = $this->request['kw'];
    if ($kw) {
      $query
        ->join('wuye_user user', 'user.id = RoomLeaseRecord.user_id', 'right')
        ->where('user.real_name|user.tel|user.word_unit', 'like', '%' . $kw . '%');
    }
  }
}